/**
 * Created by huangxuehua on 2017/12/6.
 */
//$("header>a.goBack").click(function(){
//    window.history.go(-1);
//})
var xpHome = new Vue({
    el:'#app',
    data:{
      imgBaseUrl:nUrls.imgBaseUrl,
      imgFBaseUrl:nUrls.imgFBaseUrl,
      daiYanList:[],//我的代言信息
      userInfo:{},//用户信息
      UserRebateInfo:{},//获得用户返利信息
      IsJoin:{}, //是否参加返利活动
      UserRebateMoney:{}//用户获得返利金额
    },
    methods:{
        deleteRepeat:function(arr){//过滤重复的头像  即过滤同一个人
                var res =[];
                var json = {};
                for(var i=0;i<arr.length;i++){
                    if(!json[arr[i].tx_images]){
                        res.push(arr[i].tx_images);
                        json[arr[i].tx_images] = 1;
                    }
                }
                return res;
        },
        getImage:function(url){//加载图片  处理 url为空 加载出错
            if(url){
                return xpHome.imgBaseUrl+url;
            }
        },
        getFImage:function(url){//加载图片  处理 url为空 加载出错
            if(url){
                return xpHome.imgFBaseUrl+url;
            }
        },
        getDate:function(time){//时间   年月日分
            return nUtils.dateTime(time);
        },
        getTypeAndColor:function(target,type){   //分割字符串
            var temp = "";
            if(target){
                var arr = target.split("-----");
                if(arr.length == 2){
                    if(type == 0){//颜色
                        return arr[1];
                    }else{//型号
                        return arr[0];
                    }
                }
            }
            return temp;
        },
        initData:function(){
            var GetIsJoin=window.localStorage.getItem("isUserJoin");
            if(GetIsJoin){
                xpHome.IsJoin=JSON.parse(GetIsJoin);
                //console.log("-- xpHome.IsJoin-", xpHome.IsJoin)
            }
        },
       getDaiYan:function(){ //获取代言信息
           var data={
               "access_token": userInfo.access_token
           }
           $.ajax({
               url:nUrls.getDaiYanInfo,
               type:"POST",
               data:data,
               success:function(data){
                   var result = eval('(' + data + ')');
                   if (result && result.code == 200) {
                       //console.log(" xpHome.daiYanList",result.data)
                       xpHome.daiYanList=result.data
                   }
               },
               error: function (msg) {
                   console.log("服务器内部错误",msg);
               }
           })
       },
        getUserRebateMoney:function(){  //用户获得返利金额
            var data={
                "access_token":userInfo.access_token,
            }
            $.ajax({
                url:nUrls.getUserRebateMoney,
                type:"POST",
                //data:data,
                success:function(data){
                    //console.log("++++")
                    var result = eval('('+data+')');
                    if(result && result.code == 200) {
                        xpHome.UserRebateMoney=result.tolInfo
                        console.log("--xpHome.UserRebateMoney--",xpHome.UserRebateMoney)

                    }
                },
                error:function(){
                    console.log("获取用户信息失败")
                }
            })
        },
        getUserRebateInfo:function(){  //获得订单用户返利信息
            var data={
                "access_token":userInfo.access_token,
            }
            $.ajax({
                url:nUrls.getUserRebateInfo,
                type:"POST",
                //data:data,
                success:function(data){
                    //console.log("++++")
                    var result = eval('('+data+')');
                    if(result && result.code == 200) {
                        xpHome.UserRebateInfo=result.data;
                        console.log("--UserRebateInfo--",xpHome.UserRebateInfo)
                    }
                },
                error:function(){
                    console.log("获取用户信息失败")
                }
            })
        },
        getUserInfo:function(){
            //var data ={
            //    "access_token":userInfo.access_token,
            //}
            $.ajax({
                url:nUrls.getUserInfo,
                type:"POST",
                //data:data,
                success:function(data){
                    //console.log("++++")
                    var result = eval('('+data+')');
                    if(result && result.code == 200) {
                        xpHome.userInfo=result.data
                        //console.log("--result--",result)
                    }
                },
                error:function(){
                    console.log("获取用户信息失败")
                }
            })
        },
        goErWeiMa:function(){
            var isJoin=xpHome.IsJoin.isJoin;
            console.log(isJoin)
            if(isJoin==1){
                window.location.href=serverUrl+"?r=marketing/sharereb/test#menu-image"
            }else{
                window.alert = function(name){
                    var iframe = document.createElement("IFRAME");
                    iframe.style.display="none";
                    iframe.setAttribute("src", 'data:text/plain,');
                    document.documentElement.appendChild(iframe);
                    window.frames[0].window.alert(name);
                    iframe.parentNode.removeChild(iframe);
                };
                alert('您尚未参加零元分享购活动！');
                return
            }

            //http://www.pooai.cn/wx/frontend/web/index.php?r=marketing/sharereb/test#menu-image
        },
        goRebateDetail:function(orderSn){
            window.location.href="./rebateDetail.html?order="+orderSn;
            //console.log("xpHome.UserRebateInfo",xpHome.UserRebateInfo)
        },
        goOnLine:function(){  //断网刷新
            nUtils.onLine();
        }
    }
});
$(function(){
    xpHome. initData()
    xpHome.getDaiYan();
    xpHome.getUserInfo();
    xpHome.getUserRebateInfo();//获得用户返利信息
    xpHome.getUserRebateMoney();//用户获得返利金额

})